package main

import (
	"code/pb"
	"context"
	"io"
	"log"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	conn, err := grpc.Dial(":7000", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Panic(err)
	}
	defer conn.Close()
	client := pb.NewQueryClient(conn)
	req := &pb.Request{
		Role: "test_role",
	}
	stream, err := client.Watch(context.Background(), req)
	if err != nil {
		log.Panic(err)
	}
	receiveCount := 0
	for {
		rsp, err := stream.Recv()
		if err == io.EOF {
			log.Println("end of stream")
			break
		}
		receiveCount++
		log.Printf("receive from server, receiveCount=%d, info=%s", receiveCount, rsp.Info)
	}
}
